﻿<%@ Page Title="Table Management" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true"
    CodeBehind="TableMgmt.aspx.cs" Inherits="TestJQGrid.TableMgmt" %>

<%@ Register Assembly="Trirand.Web" TagPrefix="trirand" Namespace="Trirand.Web.UI.WebControls" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
    <title></title>
    <!-- The jQuery UI theme that will be used by the grid -->
    <link rel="stylesheet" type="text/css" media="screen" href="../themes/redmond/jquery-ui-1.8.2.custom.css" />
    <!-- The jQuery UI theme extension jqGrid needs -->
    <link rel="stylesheet" type="text/css" media="screen" href="../themes/ui.jqgrid.css" />
    <!-- jQuery runtime minified -->
    <script src="../js/jquery-1.4.4.min.js" type="text/javascript"></script>
    <!-- The localization file we need, English in this case -->
    <script src="../js/trirand/i18n/grid.locale-en.js" type="text/javascript"></script>
    <!-- The jqGrid client-side javascript -->
    <script src="../js/trirand/jquery.jqGrid.min.js" type="text/javascript"></script>
    <script src="../js/trirand/jquery.jqDatePicker.min.js" type="text/javascript"></script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <br />     <br />     <br />     <br />
    <trirand:JQGrid runat="server" ID="JQGrid1" DataSourceID="SqlDataSource1" AutoWidth="True" Height="300px">
        <Columns>
            <trirand:JQGridColumn Editable="true" DataField="TableName" PrimaryKey="True" EditType="DropDown"
                EditorControlID="TableList" />
            <trirand:JQGridColumn Editable="true" DataField="ColumnName" PrimaryKey="True" />
            <trirand:JQGridColumn Editable="false" Visible="false" DataField="Editable" />
            <trirand:JQGridColumn Editable="false" Visible="false" DataField="PrimaryTableColumn" />
            <trirand:JQGridColumn Editable="true" DataField="ColumnStatus" EditType="DropDown"
                EditorControlID="StatusValues" />
            <trirand:JQGridColumn Editable="true" DataField="ColumnType" EditType="DropDown"
                EditorControlID="DataTypesList" />
            <trirand:JQGridColumn Editable="false" DataField="CreatedBy" />
            <trirand:JQGridColumn Editable="false" DataField="CreatedOn" />
        </Columns>
        <EditDialogSettings CloseAfterEditing="True" ReloadAfterSubmit="true" />
        <AddDialogSettings CloseAfterAdding="true" ReloadAfterSubmit="true" />
        <SearchDialogSettings MultipleSearch="True" />
        <ToolBarSettings ShowEditButton="true" ShowRefreshButton="True" ShowAddButton="true"
            ShowSearchButton="True" ShowViewRowDetailsButton="True" />
        <SortSettings InitialSortColumn="TableName"></SortSettings>
        <AppearanceSettings ShowRowNumbers="True" />
    </trirand:JQGrid>
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:AgentBillingConnectionString %>"
        SelectCommand="Select * from [ColumnProperties] where [TableName] IN ( select [TableName] from [TablesList] where [TableType] = 'ExternalMaster' ) OR [TableName] IN ( select [TableName] from [ProductList] where [ProductName] = @ProductName ) Order By [TableName]"
        InsertCommand="INSERT INTO [ColumnProperties] ([TableName], [ColumnName], [Editable], [ColumnStatus], [ColumnType], [CreatedBy], [CreatedOn]) VALUES (@TableName, @ColumnName, 'F', @ColumnStatus, @ColumnType, @loginId, getDate() )"
        UpdateCommand="UPDATE [ColumnProperties] SET [ColumnStatus] = @ColumnStatus, [ColumnType] = @ColumnType, [CreatedBy] = @loginId, [CreatedOn] = getDate() WHERE [TableName] = @TableName AND [ColumnName] = @ColumnName"
        DeleteCommand="DELETE FROM [ColumnProperties] WHERE [TableName] = @TableName AND [ColumnName] = @ColumnName">
        <SelectParameters>
            <asp:SessionParameter DefaultValue="'default'" Name="ProductName" Type="String" SessionField="ProductName" />
        </SelectParameters>
        <DeleteParameters>
            <asp:Parameter Name="TableName" Type="String" />
            <asp:Parameter Name="ColumnName" Type="String" />
        </DeleteParameters>
        <InsertParameters>
            <asp:Parameter Name="TableName" Type="String" />
            <asp:Parameter Name="ColumnName" Type="String" />
            <asp:Parameter Name="ColumnStatus" Type="String" />
            <asp:Parameter Name="ColumnType" Type="String" />
            <asp:SessionParameter DefaultValue="'default'" Name="loginId" Type="String" SessionField="loginId" />
        </InsertParameters>
        <UpdateParameters>
            <asp:Parameter Name="ColumnStatus" Type="String" />
            <asp:Parameter Name="ColumnType" Type="String" />
            <asp:SessionParameter DefaultValue="'default'" Name="loginId" Type="String" SessionField="loginId" />
            <asp:Parameter Name="TableName" Type="String" />
            <asp:Parameter Name="ColumnName" Type="String" />
        </UpdateParameters>
    </asp:SqlDataSource>
    <asp:SqlDataSource runat="server" ID="StatusDataSource" ConnectionString="<%$ ConnectionStrings:AgentBillingConnectionString %>"
        SelectCommand="Select [Value] from [ValidValues] where [TableName] IN ( select [AdminAccess] from [Permissions] where [UserId] = @loginId and [ProductName] = @ProductName ) and [ColumnName] = 'Status'">
        <SelectParameters>
            <asp:SessionParameter DefaultValue="'default'" Name="ProductName" Type="String" SessionField="ProductName" />
            <asp:SessionParameter DefaultValue="'default'" Name="loginId" Type="String" SessionField="loginId" />
        </SelectParameters>
    </asp:SqlDataSource>
    <asp:DropDownList runat="server" ID="TableList" DataSourceID="TableListDataSource"
        DataValueField="TableName" DataTextField="TableName" />
    <asp:SqlDataSource runat="server" ID="TableListDataSource" ConnectionString="<%$ ConnectionStrings:AgentBillingConnectionString %>"
        SelectCommand="select [TableName] from [TablesList] where [TableType] = 'ExternalMaster' OR [TableName] IN ( select [TableName] from [ProductList] where [ProductName] = @ProductName ) Order By [TableName]">
        <SelectParameters>
            <asp:SessionParameter DefaultValue="'default'" Name="ProductName" Type="String" SessionField="ProductName" />
        </SelectParameters>
    </asp:SqlDataSource>
    <asp:DropDownList runat="server" ID="StatusValues" DataSourceID="StatusDataSource"
        DataValueField="Value" DataTextField="Value" />
    <asp:SqlDataSource runat="server" ID="DataTypeDataSource" ConnectionString="<%$ ConnectionStrings:AgentBillingConnectionString %>"
        SelectCommand="select [ColumnName], [Value] from [ValidValues] where [TableName]='DataTypes' order by [ColumnName] desc">
    </asp:SqlDataSource>
    <asp:DropDownList runat="server" ID="DataTypesList" DataSourceID="DataTypeDataSource"
        DataValueField="Value" DataTextField="ColumnName" />
</asp:Content>
